package com.example.scancodelogindemo.service;


import com.example.scancodelogindemo.model.QrCodeInfo;
import com.example.scancodelogindemo.model.Result;
import org.springframework.web.context.request.async.DeferredResult;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 傲寒
 * @date 2023/12/7
 */
public class LongPollFactory {

    private static final Map<String, DeferredResult<Result<QrCodeInfo>>> ONLINE_SESSION_CLIENT_MAP = new ConcurrentHashMap<>();

    public static void put(String qrcodeId, DeferredResult<Result<QrCodeInfo>> session) {
        ONLINE_SESSION_CLIENT_MAP.put(qrcodeId, session);
    }

    public static DeferredResult<Result<QrCodeInfo>> get(String qrcodeId) {
        return ONLINE_SESSION_CLIENT_MAP.get(qrcodeId);
    }

    public static void remove(String qrcodeId) {
        ONLINE_SESSION_CLIENT_MAP.remove(qrcodeId);
    }

}
